package cn.hiapi.shop.query;

import cn.hiapi.basic.jpa.pageable.QueryWrapper;
import cn.hiapi.basic.jpa.query.BasicQuery;
import cn.hiapi.shopkeeper.enums.ActivityType;
import cn.hiapi.shopkeeper.enums.OrderStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author AdinZ
 * @date 2023/2/5 21:04
 */
@Setter
@Getter
public class ActivityOrderQuery extends BasicQuery {
    private long shopId;

    @ApiModelProperty("用户手机号,或订单编号")
    private String key;

    private Long oid;

    private Long buyerId;

    private String title;

    private OrderStatus status;

    private ActivityType activityType;

    private Long aid;


    @Override
    public QueryWrapper getQueryWrapper() {
        QueryWrapper wrapper = super.getBasicQueryWrapper();
        wrapper.eq("shopId", shopId);
        wrapper.eq("id", oid);
        wrapper.eq("aid", aid);
        wrapper.eq("activityType", activityType);
        if (status == OrderStatus.COMPLETE) wrapper.eq("useStatus", 1);
        else wrapper.eq("status", status);
        wrapper.eq("buyerId", buyerId);
        if (StringUtils.isNotEmpty(this.title)) {
            wrapper.eq("title", "%" + this.title + "%");
        }
        return wrapper;
    }
}
